.TH std::basic_filebuf::is_open 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::basic_filebuf::is_open \- std::basic_filebuf::is_open

.SH Synopsis
   bool is_open() const;

   Returns true if the most recent call to open() succeeded and there has been no call
   to close() since then.

.SH Parameters

   \fI(none)\fP

.SH Return value

   true if the associated file is open, false otherwise.

.SH Notes

   This function is typically called by std::basic_fstream::is_open().

.SH Example


// Run this code

 #include <fstream>
 #include <iostream>

 int main()
 {
     std::ifstream fs("test.txt");
     std::filebuf fb;
     fb.open("test.txt", std::ios_base::in);
     std::cout << std::boolalpha
               << "direct call: " << fb.is_open() << '\\n'
               << "through streambuf: " << fs.rdbuf()->is_open() << '\\n'
               << "through fstream: " << fs.is_open() << '\\n';
 }

.SH Output:

 direct call: true
 through streambuf: true
 through fstream: true

.SH See also

   open  opens a file and configures it as the associated character sequence
         \fI(public member function)\fP
   close flushes the put area buffer and closes the associated file
         \fI(public member function)\fP
